package Week3.J0503;

// 预处理思想

import java.io.*;
import java.util.StringTokenizer;

public class 十字爆破_xv {
    public static PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
    public static Read in = new Read();

    public static void main(String[] args) throws IOException {
        int n = in.nextInt();
        int m = in.nextInt();
        long[][] arr = new long[n][m];
        long[] rowSum = new long[n]; // 存储每行的总和
        long[] colSum = new long[m]; // 存储每列的总和

        // 读取输入矩阵，并同时计算每行和每列的总和
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                arr[i][j] = in.nextInt();
                rowSum[i] += arr[i][j];
                colSum[j] += arr[i][j];
            }
        }

        // 计算结果矩阵
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                out.print(rowSum[i] + colSum[j] - arr[i][j] + " ");
            }
            out.println();
        }
        out.close();
    }



    private static int addAll(int i, int j, int n, int m, int[][] arr) {
        int sum = 0;
        for (int k = 0; k < m; k++) {
            sum += arr[i][k];
        }
        for (int k = 0; k < n; k++) {
            sum += arr[k][j];
        }

        return sum - arr[i][j];
    }
}





class Read {//自定义快读读入
    //字符串裁剪
    StringTokenizer st = new StringTokenizer("");

    //1.字节流System.in->字符流InputStreamReader
    //2.带内存缓冲区的字符流BufferedReader
    BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));


    String next() throws IOException {
        //为什么要while循环，因为可能读取的数据不止一行，有多行就需要多次取
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(bf.readLine());//先拿一行的数据
        }
        return st.nextToken();//对这一行的数据进行裁剪，拿到第一个数据
    }

    String nextLine() throws IOException {
        return bf.readLine();
    }

    int nextInt() throws IOException {
        return Integer.parseInt(next());
    }

    long nextLong() throws IOException {
        return Long.parseLong(next());
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(next());
    }
}
